<?php

// 直接アクセスを拒否する
if (!defined("IN_APP"))
	exit("直接アクセスはできません。");

// ログインしたユーザーのみがアクセスできる
if (!isset($_SESSION['twitter_username']))
	exit("ログインしないとアクセスできません。");

if (@$_POST["action"] == "member_attendance_status_update")  {
	$connect = connectToDb();
	$user_id = mysql_real_escape_string($_POST['user_id']);
	$status =  mysql_real_escape_string($_POST['status']);
	
	$leader_id = getLeaderId($connect, $_SESSION['group']);
	
	if ($_SESSION['user_id'] == $leader_id) {
		$query = "insert into attendance ";
		$query .= "(group_id,user_id,status,date,time) ";
		$query .= "values({$_SESSION['group']},";
		$query .= "$user_id,";
		$query .= "$status,";
		$query .= "CURRENT_DATE(),";
		$query .= "CURRENT_TIMESTAMP(0)";
		$query .= ")";

		$result = mysql_query($query, $connect);

		if ($result) {
			if ($status == 1)
				$statusText = "出席";
			else 
				$statusText = "欠席";
				
			echo "success|$user_id|$statusText";
		}
		else {
			echo $MESSAGES['ATTENDANCE_STATUS_UPDATE_ERROR'];
		}
	}
	else {
		echo $MESSAGES['ATTENDANCE_STATUS_UPDATE_LEADER_ONLY'];
	}
}
?>